package com.book.service.impl;

import com.book.entity.RoleMenu;
import com.book.mapper.RoleMenuMapper;
import com.book.service.RoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

/**
 * @author SuperYu  2024/8/12
 */
@Service
public class RoleMenuServiceImpl implements RoleMenuService {

    RoleMenuMapper roleMenuMapper;

    @Autowired
    public void setRoleMenuMapper(RoleMenuMapper roleMenuMapper) {
        this.roleMenuMapper = roleMenuMapper;
    }

    @Override
    public int addRoleMenu(int roleId, int[] ids) {
        // 1:先把根据roleId把有数据删除
        Example example = new Example(RoleMenu.class);
        Example.Criteria c = example.createCriteria();
        c.andEqualTo("roleId",roleId);
        int i = roleMenuMapper.deleteByExample(example);
        if(i > 0){
            // 2: 再新增现在权限数据
           return roleMenuMapper.insertMorePermission(roleId, ids);
        }
        return 0;
    }
}
